<template>
<!--pages/company/company.ttml-->
<view class="content">
   <view class="hr"></view>
   <view class="item">
     <text>工龄：</text>
     <input type="text" @input="workAge" placeholder="工龄" placeholder-class="holder" bingblur="accountblur"></input>
   </view>
    <view class="item">
      <text>家乡：</text>
      <input type="text" @input="home" placeholder="家乡" placeholder-class="holder" bingblur="accountblur"></input>
   </view>
    <view class="item">
      <text>熟练度：</text>
      <picker class="picker" @change="bindProficiencyChange" :value="proficiency" :range="proficiency">
        <view class="picker">
          {{proficiency[proficiencyIndex]}}
        </view>
      </picker>
    </view>
    <view class="item">
    <text>人员构成：</text>
      <picker class="picker" @change="bindStaffCompositionChange" :value="composition" :range="composition">
        <view class="picker">
          {{composition[compositionIndex]}}
        </view>
      </picker>
    </view>
   <view class="item" v-if="compositionIndex!=0 && compositionIndex!=1">
      <text>队伍人数：</text>
      <input type="text" @input="num" placeholder="队伍人数" placeholder-class="holder" bingblur="accountblur"></input>
   </view>
    <button class="btn" :disabled="disabled" type="primary" form-type="submit" @tap="commit">保存资料</button>
</view>
</template>

<script>
// pages/ucenter/personnel/personnel.js
let app = getApp();

export default {
  data() {
    return {
      proficiency: ["", "学徒工（小工）", "中级工（中工）", "高级工（大工）"],
      composition: ["", "个人", "班组", "施工队", "突击队"],
      form: {
        proficiency: "",
        composition: "",
        workAge: "",
        home: "",
        num: 1
      },
      proficiencyIndex: 0,
      compositionIndex: 0
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
  methods: {
    bindProficiencyChange(e) {
      console.log("picker发送选择改变，携带值为", e.detail.value);
      let form = this.form;
      form.proficiency = e.detail.value;
      this.setData({
        form,
        proficiencyIndex: e.detail.value
      });
    },

    bindStaffCompositionChange(e) {
      console.log("picker发送选择改变，携带值为", e.detail.value);
      let form = this.form;
      form.composition = e.detail.value;
      this.setData({
        form,
        compositionIndex: e.detail.value
      });
    },

    workAge(e) {
      let form = this.form;
      form.workAge = e.detail.value;
      this.setData({
        form
      });
    },

    home(e) {
      let form = this.form;
      form.home = e.detail.value;
      this.setData({
        form
      });
    },

    num(e) {
      let form = this.form;
      form.num = e.detail.value;
      this.setData({
        form
      });
    },

    commit(e) {
      var that = this;
      uni.request({
        url: `${app.globalData.baseUrl}/mallappletbackstage/personnel-info/getInfo/${uni.getStorageSync('openid')}`,
        method: "GET",
        success: res => {
          console.log(res.data.dataMap.data);

          if (res.data.dataMap.data) {
            uni.request({
              url: `${app.globalData.baseUrl}/mallappletbackstage/personnel-info/upDataInfo/${uni.getStorageSync('openid')}`,
              method: "POST",
              data: that.form,
              success: res => {
                uni.navigateTo({
                  url: "/pages/ucenter/recruit/recruit",

                  success(res1) {
                    uni.showToast({
                      title: '更新成功',
                      icon: 'none',
                      duration: 4000
                    });
                  }

                });
              }
            });
          } else {
            uni.request({
              url: `${app.globalData.baseUrl}/mallappletbackstage/personnel-info/addInfo/${uni.getStorageSync('openid')}`,
              method: "POST",
              data: that.form,
              success: res => {
                uni.navigateTo({
                  url: "/pages/ucenter/recruit/recruit",

                  success(res1) {
                    uni.showToast({
                      title: '提交成功',
                      icon: 'none',
                      duration: 4000
                    });
                  }

                });
              }
            });
          }
        },

        fail(res) {
          console.log(res);
        }

      });
    }

  }
};
</script>
<style>
/* pages/company/company.ttss */
.content{
  width: 100%;
  height: 700px;
  background-color: #f2f2f2;
}
.hr{
  padding-top: 40px;
}
.item{
  background: #ffffff;
  width: 96%;
  height: 100rpx;
  line-height: 100rpx;
  margin: 2%;
  padding: 0rpx 20rpx;
}
.item text {
  float: left;
  height: 100rpx;
  width: 25%;
}
.item input{
  float: left;
  height: 100rpx;
  width: 75%;
}
.holder{
  font-size: 14px;
  color: #999999;
}
.flex{
  display: flex;
  flex-direction: row;
}
.flex input{
  width: 300px;
}
item switch{
  margin-top: 5px;
  margin-right: 5px;
}
.mobileInfo{
  display: flex;
  flex-direction: row;
}
.mobile{
  margin: 0 auto;
  border: 1px solid #cccccc;
  height: 40px;
  width: 50%;
  border-radius: 3px;
  background-color: #ffffff;
  margin-bottom: 15px;
  display: flex;
  flex-direction: row;
  margin-left: 5%; 
}
.mobile input{
  margin-top: 8px;
  margin-left: 10px;
}
.code{
  border: 1px solid #cccccc;
  height: 40px;
  width: 35%;
  background-color: #edeeec;
  border-radius: 3px;
  text-align: center;
  margin-left: 10px;
  line-height: 40px;
  color: #999999;
  font-size: 15px;
  margin-bottom: 15px;
  margin-right: 5%; 
}
.btn{
  width: 90%;
  color: #999999;
  margin-top: 40px;
}
.xieyi{
  margin-top: 15px;
  margin-left: 15px;
  font-size: 13px;
}
.agree{
  margin-left: 5px;
  color: #666666; 
}
.opinion{
  color: red;
  font-weight: bold;
  text-decoration: underline;
}
.picker{
  height: 90rpx;
}

</style>